<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="public/static" /}
    <style>
        .operating{
            display: none;
        }
        .layui-table tr{
            cursor: pointer;
        }
        .layui-table tr:hover > td .operating{
            display: block;
        }
    </style>
</head>
<body>

{include file="public/nav" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    {eq name="check.MenumenuAdd" value="1"}
                        <button class="layui-btn" onclick="common.openWindow('新增菜单','{:url('Menu/menuAdd',['pid'=>0])}','500','380')" >
                            <i class="layui-icon">&#xe654;</i>新增菜单
                        </button>
                    {/eq}
                    {eq name="check.MenumenuDelAll" value="1"}
                        <button class="layui-btn layui-btn-danger" onclick="dataDelAll()">
                            <i class="layui-icon">&#xe640;</i>批量删除
                        </button>
                    {/eq}
                </div>
                <div class="layui-card-body layui-table-body">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" lay-filter="checkbox" name="id" value="" lay-skin="primary">
                                </th>
                                <th>菜单名</th>
                                <th>链接</th>
                                <th>状态</th>
                                <th width="220">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {volist name="info" id="vo"}
                                <tr cate-id="{$vo.me_id}" fid="{$vo.me_pid}" level="{$vo.level}">
                                    <td>
                                        <input type="checkbox" name="id[]" value="{$vo.me_id}" lay-skin="primary">
                                    </td>
                                    <td><i class="layui-icon x-show" status='true'>|-</i> {$vo.me_name}</td>
                                    <td>{$vo.me_url}</td>
                                    <td>
                                        {eq name="vo.me_status" value="1"}
                                            <span class="layui-badge layui-bg-green">启用</span>
                                        {else/}
                                            <span class="layui-badge">禁用</span>
                                        {/eq}
                                    </td>
                                    <td>
                                        <div class="operating">
                                            {eq name="check.MenumenuAdd" value="1"}
                                                <a href="javascript:;" onclick="common.openWindow('新增下级','{:url('Menu/menuAdd',['pid'=>$vo.me_id])}','500','380')" >
                                                    <i class="layui-icon">&#xe654;</i>新增下级
                                                </a>
                                            {/eq}
                                            {eq name="check.MenumenuEdit" value="1"}
                                                <a href="javascript:;" onclick="common.openWindow('编辑','{:url('Menu/menuEdit',['id'=>$vo.me_id])}','500','380')" >
                                                    <i class="layui-icon">&#xe642;</i>编辑
                                                </a>
                                            {/eq}
                                            {eq name="check.MenumenuDel" value="1"}
                                                <a href="javascript:;" onclick="dataDel(this,'{$vo.me_id}')" >
                                                    <i class="layui-icon">&#xe640;</i>删除
                                                </a>
                                            {/eq}
                                        </div>
                                    </td>
                                </tr>
                            {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /*分类展开收起的分类的逻辑*/
    $(function() {
        //获取所有cate-id
        $("tr").each(function () {
            var cateIds = $(this).attr("cate-id");
            //显示所有栏目
            for (var i in cateIds) {
                var cate = $("tbody tr[cate-id=" + cateIds + "]");
                //所在层次，对应多少左内边距
                var marginLeft = cate.attr('level') * 15;
                cate.find('.x-show').css('margin-left', marginLeft + 'px');
            }
        });
    });
    /*全选*/
    common.selectCheckbox('checkbox','id[]');
    /*批量删除*/
    function dataDelAll() {
        //获取checkbox值
        var ids = common.getCheckboxVal();
        if(ids.length < 1){
            layer.msg('请选择需要操作的数据！',{time:1500, icon:5});
            return false;
        }
        layer.confirm('确认要删除选中的数据吗？',function(){
            var index = layer.load();
            $.ajax({
                type: 'POST',
                url: "{:url('Menu/menuDelAll')}",
                data: {ids:ids},
                dataType:'json',
                success:function(data){
                    if(data.status === 1){
                        layer.msg(data.info,{time:1500, icon:6},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data.info,{time:1500, icon:5});
                    }
                    layer.close(index);
                },
                error:function(){
                    console.log(data.msg);
                    layer.msg("不好意思，出现了一点问题", {icon: 5});
                }
            });
        });
    }
    /*删除*/
    function dataDel(obj, id){
        layer.confirm('确认要删除这条数据吗？',function(){
            var index = layer.load();
            //发异步删除数据
            $.ajax({
                type:"post",
                url:"{:url('Menu/menuDel')}",
                data:{id:id},
                dataType:'json',
                success:function (data) {
                    if(data.status === 1){
                        $(obj).parents("tr").remove();
                        layer.msg(data.info, {icon: 6,time:1500});
                    }else{
                        layer.msg(data.info, {icon: 5,time:1500});
                    }
                    layer.close(index);
                },
                error:function (data) {
                    console.log(data);
                    layer.msg("不好意思，出现了一点问题", {icon: 5});
                }
            });
        });
    }
</script>
</html>